// 笔试强训：十字爆破

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<vector<int>> vv(n, vector<int>(m, 0));
    vector<long long> rowSums(n, 0);
    vector<long long> colSums(m, 0);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            scanf("%d", &vv[i][j]);
            rowSums[i] += vv[i][j];
            colSums[j] += vv[i][j];
        }
    }

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cout << rowSums[i] + colSums[j] - vv[i][j] << " ";
        }
        cout << endl;
    }
}